import { ActionContext, ActionTree, GetterTree, MutationTree } from 'vuex'
import axios from '../../extend/axios'

interface MenuTips {
  orderCount: string | number
  inquiryCount: string | number
  countBill: string | number
}

interface BillTips {
  paperTicketCount: string | number
  pendingReviewCount: string | number
  electricTicketCount: string | number
  pendingInquiryCount: string | number
}

interface OfferTips {
  tobeAdjustedCount: string | number
  employerQuotedCount: string | number
  priceCount: string | number
  inInquiryCount: string | number
  biddingCount: string | number
}

interface UnreadTips {
  billCount: string | number
  txnCount: string | number
  sysCount: string | number
  allCount: string | number
}

interface OrderTips {
  all_sum: string | number
  one_order_sum: string | number
  one_sum: string | number
  one_to_endorse_sum: string | number
  one_to_release_sum: string | number
  order_sum: string | number
  to_endorse_sum: string | number
  to_release_sum: string | number
  zero_order_sum: string | number
  zero_sum: string | number
  zero_to_endorse_sum: string | number
  zero_to_release_sum: string | number
}

class State {
  public menuTips: MenuTips = {
    orderCount: '',
    inquiryCount: '',
    countBill: ''
  }
  public billTips: BillTips = {
    paperTicketCount: '',
    pendingReviewCount: '',
    electricTicketCount: '',
    pendingInquiryCount: ''
  }
  public offerTips: OfferTips = {
    tobeAdjustedCount: '',
    priceCount: '',
    employerQuotedCount: '',
    inInquiryCount: '',
    biddingCount: ''
  }
  public unreadTips: UnreadTips = {
    billCount: '',
    txnCount: '',
    sysCount: '',
    allCount: ''
  }
  public orderTips: OrderTips = {
    all_sum: '',
    one_order_sum: '',
    one_sum: '',
    one_to_endorse_sum: '',
    one_to_release_sum: '',
    order_sum: '',
    to_endorse_sum: '',
    to_release_sum: '',
    zero_order_sum: '',
    zero_sum: '',
    zero_to_endorse_sum: '',
    zero_to_release_sum: ''
  }
}

const mutations = {
  setMenuTips (state: State, res: AjaxResponse) {
    state.menuTips = res.data
  },
  setBillTips (state: State, res: AjaxResponse) {
    state.billTips = res.data
  },
  setOfferTips (state: State, res: AjaxResponse) {
    state.offerTips = res.data
  },
  setUnreadTips (state: State, res: AjaxResponse) {
    state.unreadTips = res.data
  },
  setOrderTips (state: State, res: AjaxResponse) {
    state.orderTips = res.data
  }
} as MutationTree<State>
const actions = {
  async getMenusTips (store: ActionContext<State, any>) {
    let res = await axios.get('b/boms/businesscount/menuremind')
    store.commit('setMenuTips', res)
  },
  async getBillsTips (store: ActionContext<State, any>) {
    let res = await axios.get('b/boms/businesscount/billremind')
    store.commit('setBillTips', res)
  },
  async getOfferTips (store: ActionContext<State, any>) {
    let res = await axios.get('b/boms/businesscount/inquiryremind')
    store.commit('setOfferTips', res)
  },
  async getUnreadTips (store: ActionContext<State, any>) {
    let res = await axios.post('b/boms/message/notice/unread/statistics')
    store.commit('setUnreadTips', res)
  },
  async getOrderTips (store: ActionContext<State, any>) {
    let res = await axios.get('b/boms/order/getOrderSumNum')
    store.commit('setOrderTips', res)
  }
} as ActionTree<State, any>
const getters = {
  menuTips (state: State) {
    return state.menuTips
  },
  billTips (state: State) {
    return state.billTips
  },
  offerTips (state: State) {
    return state.offerTips
  },
  orderTips (state: State) {
    return state.orderTips
  },
  unreadTips (state: State) {
    return state.unreadTips
  }
} as GetterTree<State, any>
const tips = {
  namespace: true,
  state: new State(),
  mutations,
  actions,
  getters
}
export default tips
